<template>
  <div class="my-tag">
    <input @keydown.enter="changeName" @blur="flag = false" v-model="product" v-if="flag" v-focus class="input" type="text" placeholder="输入标签" />
    <div @dblclick="flag = true" v-else class="text">{{value}}</div>
  </div>
</template>

<script>
export default {
  name: "MyTag",
  props:{
    value:{
      type: String,
      required: true
    }
  },
  data() {
    return {
      flag: false,
      product: ''
    };
  },
  methods:{
    changeName(){
      this.flag = false
      this.$emit('input',this.product)
    }
  }
};
</script>

<style lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>
